package com.ziyue.socket.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ziyue.socket.bean.change.ChangeActivityRequest;
import com.ziyue.socket.bean.change.ChangeActivityResponse;
import com.ziyue.socket.bean.change.ChangeQuestionRequest;
import com.ziyue.socket.bean.change.ChangeQuestionResponse;
import com.ziyue.socket.cache.ChangeService;
import com.ziyue.socket.enums.OptionEnum;
import com.ziyue.socket.exception.UnFullWebsocketMessageException;
import com.ziyue.socket.service.OptionAbstract;
import io.netty.channel.Channel;

/**
 * Created by wancheng on 2019/4/20.
 */
public class ChangeQuestion extends OptionAbstract {

    private final OptionEnum OPTION = OptionEnum.CHANGE_QUESTION;

    @Override
    public Object send(Channel channel, String requestBody) throws Exception {

        ChangeQuestionRequest request = JSONObject.parseObject(requestBody, ChangeQuestionRequest.class);
        if (request.getQuestionId() == null) {
            throw new UnFullWebsocketMessageException("无更换题号");
        }

        ChangeService.changeQuestion(channel, request.getQuestionId());
        sendStudent(channel, "更换当前题号", new ChangeQuestionResponse(request.getQuestionId()), OPTION);
        return null;
    }

    @Override
    public Object get(Channel channel, String requestBody) {
        return null;
    }
}
